/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.escom.cliente.exception;

import com.escom.administracionperfiles.constants.Constants;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.MissingResourceException;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;


/**
 *
 * @author yamil
 */
public abstract class ADMINException extends Exception {

	private Throwable throwable;
	private String errorCode;
	private ResourceBundle resourcesError = ResourceBundle.getBundle(Constants.ERROR_PROPERTIES_HANDLED, new Locale("es", "MX"));

	protected ADMINException(String errorCode, Throwable throwable) {
		this.throwable = throwable;
		this.errorCode = errorCode;
	}

	public void printStackTrace() {
		if (throwable != null) {
			throwable.printStackTrace();
		} else {
			super.printStackTrace();
		}
	}

    @Override
	public void printStackTrace(PrintStream s) {
		if (throwable != null) {
			throwable.printStackTrace(s);
		} else {
			super.printStackTrace(s);
		}
	}

    @Override
	public void printStackTrace(PrintWriter s) {
		if (throwable != null) {
			throwable.printStackTrace(s);
		} else {
			super.printStackTrace(s);
		}
	}

    @Override
	public String getMessage() {
		String keyStr = "";
		try {
			keyStr = resourcesError.getString(errorCode);
		} catch (MissingResourceException e) {
			keyStr = Constants.ERROR_PROPERTIES_GETPROPERTYERROR;
		}
		return errorCode + " : " + keyStr;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public Throwable getThrowable() {
		return throwable;
	}

	public void setErrorCode(String string) {
		errorCode = string;
	}

	public void setThrowable(Throwable throwable) {
		this.throwable = throwable;
	}

}
